package net.lab1024.sa.admin.module.business.file.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.admin.module.business.file.dao.DocmentaaDao;
import net.lab1024.sa.admin.module.business.file.domain.entity.DocmentaaEntity;
import net.lab1024.sa.admin.module.business.file.domain.form.add.DocmentaaAddForm;
import net.lab1024.sa.admin.module.business.file.domain.form.query.DocmentaaQueryForm;
import net.lab1024.sa.admin.module.business.file.domain.form.update.DocmentaaUpdateForm;
import net.lab1024.sa.admin.module.business.file.domain.vo.DocmentaaVO;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 生产订单与机器对应表 Service
 *
 * @Author AKITA
 * @Date 2025-07-09 15:18:23
 * @Copyright AKITA
 */

@Service
public class DocmentaaService {

    @Resource
    private DocmentaaDao docmentaaDao;

    /**
     * 分页查询
     */
    public PageResult<DocmentaaVO> queryPage(DocmentaaQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<DocmentaaVO> list = docmentaaDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(DocmentaaAddForm addForm) {
        DocmentaaEntity docmentaaEntity = SmartBeanUtil.copy(addForm, DocmentaaEntity.class);
        Integer lineNum = docmentaaDao.selectMaxLineNum(addForm.getDocEntry());
        docmentaaEntity.setLineNum(++lineNum);
        docmentaaDao.insert(docmentaaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     */
    public ResponseDTO<String> update(DocmentaaUpdateForm updateForm) {
        DocmentaaEntity docmentaaEntity = SmartBeanUtil.copy(updateForm, DocmentaaEntity.class);
        docmentaaDao.updateById(docmentaaEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)) {
            return ResponseDTO.ok();
        }

        docmentaaDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long docEntry) {
        if (null == docEntry) {
            return ResponseDTO.ok();
        }

        docmentaaDao.deleteById(docEntry);
        return ResponseDTO.ok();
    }
}
